/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package data;
import java.io.*;
import java.util.*;


/**
 *
 * @author Isaac Noble
 */
public class LocalData {

    private static String data_dir = "data/";

    private static LocalData data_loader = new LocalData();

    public enum Input
    {
        GEO_FILE ("geo.csv"),
        HOUSEHOLD_FILE ("households.csv"),
        BANK_FILE ("banks.csv"),
        US_HOUSE_PRICES ("USHousingPrices.csv"),
        US_SHAPE_FILE ("us_shape.csv"),
        US_UNEMPLOYMENT_DATA ("unemployment.csv");

        private final String file_name;

        Input(String file)
        {
            file_name = file;
        }

        public String GetFileName()
        {
            return file_name;
        }
    }

    private static HashMap<Input,File> files = new HashMap<Input,File>();



    public static File GetFile(Input input)
    {
        if(!files.containsKey(input))
        {
            String path = data_dir + input.GetFileName();
            java.net.URL data_url = data_loader.getClass().getResource(path);
            File new_file = new File(data_url.getPath().replaceAll("%20", " "));
            files.put(input, new_file);
        }
        return files.get(input);
    }

    public static InputStream GetInputStream(Input input)
    {
        String path = data_dir + input.GetFileName();
        return data_loader.getClass().getResourceAsStream(path);
    }
}
